<?php
class comment extends top {

    function __construct(){  
        parent::__construct();
        // if(!$this->check_session())
            // $this->__error("danger","未登录!"); 
    }
    function comment_list(){
        $data=$this->spArgs();
        
        $m_comment = spClass('m_comment');
        $conditions = array("article_id"=>$data["article_id"]);
        $comment = $m_comment->findAll($conditions);
        foreach ($comment as $key => $val) {
            $arr[]= array(
                'comment_id'   => $val['id'],
                'comment_content'  => $val['content'],
                'add_time'  => $val['add_time'],
                'user_id' => $val['user_id'],
                'user_name' => $val['user_name']
            );
        }

        echo json_encode($arr);
    }
    //创建文章
    function add_comment(){
        $data=$this->spArgs();

        $m_comment = spClass('m_comment');

        if(!empty($data["content"])){
            $insert = array(
                'article_id' => $data['article_id'],
                'content' => $data['content'],
                'user_id' => $data['user_id'],
                'user_name' => $data['user_name'],
                'add_time'=>date('Y-m-d H:i:s')                
            );
            $a = $m_comment->create($insert);
            if($a){
                $conditions = array("add_time"=>$insert['add_time']);
                $comment = $m_comment->findAll($conditions);
                echo json_encode($comment);
                // echo 1;
            }          
        }else{
            $this->__error("danger","评论失败!");
        }

    }
}
?>